﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.PopulationUI {
    import flash.events.*;
    import flash.display.*;
    import flash.utils.*;
    import Display.DialogUI.*;
    import org.aswing.*;
    import Classes.*;
    import org.aswing.geom.*;
    import flash.text.*;
    import org.aswing.ext.*;
    import Display.aswingui.*;
    import Engine.*;

    public class PopulationDetailDialogView extends GenericDialogView {

        public static const HR_OFFSET:int = 11;
        public static const TIP_MARGIN:int = 10;

        protected var m_popNumber:JTextField;
        protected var m_popCapNumber:JTextField;
        protected var m_happinessText:JLabel;
        protected var m_gridList:GridList;
        protected var m_cellFactory:GridListCellFactory;
        protected var m_model:VectorListModel;

        public function PopulationDetailDialogView(_arg1:Dictionary, _arg2:String="", _arg3:String="", _arg4:int=0, _arg5:Function=null){
            super(_arg1, _arg2, _arg3, _arg4, _arg5);
            this.setLayout(new SoftBoxLayout(SoftBoxLayout.Y_AXIS, 0, SoftBoxLayout.TOP));
        }
        override protected function init():void{
            var _local1:Array = [m_assetDict["population_bg_happy"], m_assetDict["population_bg_neutral"], m_assetDict["population_bg_sad"]];
            var _local2:int = Global.world.citySim.getHappinessState();
            m_bgAsset = (new (_local1[_local2])() as DisplayObject);
            this.makeBackground();
            this.makeCenterPanel();
            ASwingHelper.prepare(this);
        }
        override protected function makeBackground():void{
            var _local1:MarginBackground;
            if (m_bgAsset){
                _local1 = new MarginBackground(m_bgAsset);
                this.setBackgroundDecorator(_local1);
            };
        }
        override protected function makeCenterPanel():void{
            this.setBackgroundDecorator(new AssetBackground(m_bgAsset));
            this.setPreferredSize(new IntDimension(m_bgAsset.width, m_bgAsset.height));
            this.setMaximumSize(new IntDimension(m_bgAsset.width, m_bgAsset.height));
            this.setMinimumSize(new IntDimension(m_bgAsset.width, m_bgAsset.height));
            this.appendAll(this.makeTopPanel(), this.makeBottomPanel());
            ASwingHelper.prepare(this);
        }
        protected function makeTopPanel():JPanel{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel();
            _local1.appendAll(ASwingHelper.horizontalStrut(110), this.makeInfoAndClosePanel());
            _local1.setPreferredSize(new IntDimension(440, 188));
            _local1.setMaximumSize(new IntDimension(440, 188));
            _local1.setMinimumSize(new IntDimension(440, 188));
            ASwingHelper.prepare(_local1);
            return (_local1);
        }
        protected function makeInfoAndClosePanel():JPanel{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanelVertical();
            _local1.appendAll(this.makePopulationAndClosePanel(), this.makeInfoPanel());
            ASwingHelper.prepare(_local1);
            return (_local1);
        }
        protected function makePopulationAndClosePanel():JPanel{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            _local1.appendAll(this.makePopulationPanel(), this.makeCloseButtonPanel());
            ASwingHelper.prepare(_local1);
            return (_local1);
        }
        protected function makeCloseButtonPanel():JPanel{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP);
            var _local2:JButton = ASwingHelper.makeMarketCloseButton();
            _local2.addEventListener(MouseEvent.CLICK, onCancelX, false, 0, true);
            _local1.append(_local2);
            ASwingHelper.setEasyBorder(_local2, 2, 4, 2, 2);
            ASwingHelper.prepare(_local1);
            return (_local1);
        }
        protected function makePopulationPanel():JPanel{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanelVertical();
            _local1.setPreferredSize(new IntDimension(295, 65));
            _local1.setMaximumSize(new IntDimension(295, 65));
            _local1.setMinimumSize(new IntDimension(295, 65));
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            var _local3:JPanel = ASwingHelper.makeSoftBoxJPanel();
            var _local4:JPanel = ASwingHelper.makeSoftBoxJPanel();
            var _local5:JPanel = ASwingHelper.makeSoftBoxJPanelVertical();
            var _local6:JPanel = ASwingHelper.makeSoftBoxJPanelVertical();
            var _local7:TextFormat = new TextFormat();
            var _local8:TextFormat = new TextFormat();
            _local7.align = "left";
            _local8.align = "right";
            var _local9:JTextField = ASwingHelper.makeTextField((ZLoc.t("Main", "Population") + " "), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 12, 16759693, 0, _local8);
            var _local10:JTextField = ASwingHelper.makeTextField((ZLoc.t("Main", "PopulationCap") + " "), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 12, 16759693, 0, _local8);
            _local5.appendAll(ASwingHelper.verticalStrut(14), _local9, ASwingHelper.verticalStrut(7), _local10);
            ASwingHelper.prepare(_local5);
            _local3.append(_local5);
            ASwingHelper.prepare(_local3);
            this.m_popNumber = ASwingHelper.makeTextField(("" + Global.world.citySim.getScaledPopulation()), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 18, 16759693, 0, _local7);
            this.m_popCapNumber = ASwingHelper.makeTextField(("" + Global.world.citySim.getScaledPopulationCap()), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 18, 16759693, 0, _local7);
            _local6.appendAll(ASwingHelper.verticalStrut(10), this.m_popNumber, this.m_popCapNumber);
            ASwingHelper.prepare(_local6);
            _local4.append(_local6);
            ASwingHelper.prepare(_local4);
            _local2.appendAll(_local3, _local4);
            ASwingHelper.prepare(_local2);
            _local1.append(_local2);
            ASwingHelper.prepare(_local1);
            return (_local1);
        }
        protected function makeInfoPanel():JPanel{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanelVertical();
            _local1.setPreferredSize(new IntDimension(330, 125));
            _local1.setMaximumSize(new IntDimension(330, 125));
            _local1.setMinimumSize(new IntDimension(330, 125));
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            var _local3:int = Global.world.citySim.getHappinessState();
            this.m_happinessText = ASwingHelper.makeLabel(ZLoc.t("Main", ("HappinessState_" + _local3)), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 18, 5296949);
            _local2.append(this.m_happinessText);
            ASwingHelper.prepare(_local2);
            var _local4:AssetPane = ASwingHelper.makeMultilineText(ZLoc.t("Main", ("PopulationPopupTipDetailed_" + _local3)), (330 - (2 * TIP_MARGIN)), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, "left", 14, 13404265);
            ASwingHelper.setEasyBorder(_local4, 0, TIP_MARGIN, 0, TIP_MARGIN);
            _local1.appendAll(_local2, ASwingHelper.verticalStrut(10), _local4);
            ASwingHelper.prepare(_local1);
            return (_local1);
        }
        protected function makeBottomPanel():JPanel{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            _local1.setPreferredSize(new IntDimension(440, 135));
            _local1.setMaximumSize(new IntDimension(440, 135));
            _local1.setMinimumSize(new IntDimension(440, 135));
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanelVertical();
            _local2.appendAll(this.makeGridTitlePanel(), this.makeGridListPanel());
            ASwingHelper.prepare(_local2);
            _local1.append(_local2);
            ASwingHelper.prepare(_local1);
            return (_local1);
        }
        protected function makeGridTitlePanel():JPanel{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER, 10);
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            var _local3:AssetPane = new AssetPane((new (m_assetDict["population_horizontalRule"])() as DisplayObject));
            var _local4:AssetPane = new AssetPane((new (m_assetDict["population_horizontalRule"])() as DisplayObject));
            var _local5:JTextField = ASwingHelper.makeTextField(ZLoc.t("Dialogs", "municipal_menu"), EmbeddedArt.TITLE_FONT, 14, 3382725);
            _local2.append(_local5);
            ASwingHelper.prepare(_local2);
            ASwingHelper.setEasyBorder(_local3, HR_OFFSET);
            ASwingHelper.setEasyBorder(_local4, HR_OFFSET);
            _local1.appendAll(_local3, _local2, _local4);
            ASwingHelper.prepare(_local1);
            return (_local1);
        }
        protected function makeGridListPanel():JPanel{
            var _local4:int;
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            var _local2:Array = Global.gameSettings.getCurrentBuyableItems("municipal");
            this.m_model = new VectorListModel();
            var _local3:int;
            while (_local3 < 4) {
                _local4 = MathUtil.randomIndex(_local2);
                this.m_model.append(_local2[_local4]);
                _local2.splice(_local4, 1);
                _local3++;
            };
            this.m_cellFactory = new PopulationMunicipalCellFactory();
            this.m_gridList = new GridList(this.m_model, this.m_cellFactory, 4, 1);
            this.m_gridList.setPreferredSize(new IntDimension(440, 135));
            this.m_gridList.setMaximumSize(new IntDimension(440, 135));
            this.m_gridList.setMinimumSize(new IntDimension(440, 135));
            ASwingHelper.prepare(this.m_gridList);
            _local1.appendAll(ASwingHelper.horizontalStrut(6), this.m_gridList);
            ASwingHelper.prepare(_local1);
            return (_local1);
        }

    }
}//package Display.PopulationUI 
